<template>
    <!-- 结算查询 -->
    <div class="container">
        <!-- 表单栏 -->
        <el-row class="form-container">
            <el-col :span="24" class="form-container">
                <el-form :inline="true" :model="formInline">
                    <el-form-item label="结算日期">
                        <el-col :span="11">
                            <el-date-picker type="date" placeholder="选择日期" v-model="formInline.dateFrom"
                                            style="width: 100%;"></el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-date-picker type="date" placeholder="选择时间" v-model="formInline.dateTo"
                                            style="width: 100%;"></el-date-picker>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="营运单位">
                        <el-autocomplete
                                class="inline-input"
                                v-model="formInline.comp"
                                :fetch-suggestions="querySearch"
                                placeholder="请输入内容">
                        </el-autocomplete>
                    </el-form-item>
                    <el-form-item label="汇总单号">
                        <el-input v-model="lineList.num"></el-input>
                    </el-form-item>
                    <el-form-item label="线路">
                        <el-autocomplete
                                class="inline-input"
                                v-model="formInline.lines"
                                :fetch-suggestions="querySearchLine"
                                placeholder="请输入内容">
                        </el-autocomplete>
                    </el-form-item>
                    <el-form-item label="车牌号">
                        <el-autocomplete
                                class="inline-input"
                                v-model="formInline.line"
                                :fetch-suggestions="querySearchCarNum"
                                placeholder="请输入内容">
                        </el-autocomplete>
                    </el-form-item>
                    <el-form-item label="单据状态">
                        <el-select v-model="formInline.state">
                            <el-option label="不限" value=""></el-option>
                            <el-option label="正常" value="0"></el-option>
                            <el-option label="作废" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item class="rf">
                        <button class="check-btn" @click="del" type="button"><img
                                src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">作废
                        </button>
                    </el-form-item>
                    <el-form-item class="rf">
                        <button class="check-btn" @click="loadList" type="button"><img
                                src="../../assets/imgs/operation_btn_icon_chongzhi_default.png" alt="" class="btn-img">重置
                        </button>
                    </el-form-item>
                    <el-form-item class="rf">
                        <button class="check-btn" @click="check" type="button"><img
                                src="../../assets/imgs/operation_btn_icon_chaxun_default.png" alt="" class="btn-img">查询
                        </button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
        <!-- 表格栏 -->
        <avue-crud ref="crud" v-model="feeTatols" :data="accountTabled.data" :option="accountTabled.option" @current-row-change="rowChange"
                   :page="accountTabled.page" @current-change="accountPage"></avue-crud>
    </div>
</template>

<script>
    const DIC = {
        Comp: [],
        State: [],
        Line: []
    }
    export default {
        data: function () {
            return {
                feeTatols:{},
                formInline: {
                    dateFrom: "",
                    dateTo: "",
                    state: "",
                    comp: "",
                    num: "",
                    lines: "",
                    line: "",
                    carNum: ""
                },
                compList: [],
                lineList: [],
                carNumList: [],
                currentRow: "",
                accountTabled: {
                    page: {
                        pageSizes: [10],
                        total: 20,
                        currentPage: 1,
                        pageSize: 10,
                    },
                    data: [],
                    option: {
                        sumText: '合计',
                        showSummary: true,
                        sumColumnList: [],
                        menu: false,
                        page: true,
                        highlightCurrentRow: true,
                        index: true,
                        column: [
                            {
                                label: "单号",
                                prop: "no"
                            },
                            {
                                label: "结算日期",
                                prop: "gather_date"
                            },
                            {
                                label: "状态",
                                prop: "state"
                            },
                            {
                                label: "营运单位",
                                prop: "balance_company_name"
                            },
                            {
                                label: "车牌号",
                                prop: "vehinos"
                            },
                            {
                                label: "线路",
                                prop: "line_names"
                            },
                            {
                                label: "发班单(正)",
                                prop: "bill_count",
                            },
                            {
                                label: "发班单(加)",
                                prop: "bill_count_ot",
                                formatter: function (row, value, label, column) {
                                    if (row.bill_count_ot == 0) {
                                        return 0
                                    } else {
                                        return row.bill_count_ot
                                    }
                                }
                            },
                            {
                                label: "人数(正)",
                                prop: "people_count",
                                formatter: function (row, value, label, column) {
                                    if (row.people_count == 0) {
                                        return 0
                                    } else {
                                        return row.people_count
                                    }
                                }
                            },
                            {
                                label: "人数(加)",
                                prop: "people_count_ot",
                                formatter: function (row, value, label, column) {
                                    if (row.people_count_ot == 0) {
                                        return 0
                                    } else {
                                        return row.people_count_ot
                                    }
                                }
                            },
                            {
                                label: "票款(正)",
                                prop: "tk_price_sum",
                                formatter: function (row, value, label, column) {
                                    if (row.tk_price_sum == 0) {
                                        return 0
                                    } else {
                                        return row.tk_price_sum
                                    }
                                }
                            },
                            {
                                label: "票款(加)",
                                prop: "tk_price_sum_ot",
                                formatter: function (row, value, label, column) {
                                    if (row.tk_price_sum_ot == 0) {
                                        return 0
                                    } else {
                                        return row.tk_price_sum_ot
                                    }
                                }
                            },
                            {
                                label: "站务费",
                                prop: "fee_zhanwu",
                                formatter: function (row, value, label, column) {
                                    if (row.fee_zhanwu == 0) {
                                        return 0
                                    } else {
                                        return row.fee_zhanwu
                                    }
                                }
                            },
                            {
                                label: "代理费",
                                prop: "fee_daili",
                                formatter: function (row, value, label, column) {
                                    if (row.fee_daili == 0) {
                                        return 0
                                    } else {
                                        return row.fee_daili
                                    }
                                }
                            },
                            {
                                label: "发班费",
                                prop: "fee_faban",
                                formatter: function (row, value, label, column) {
                                    if (row.fee_faban == 0) {
                                        return 0
                                    } else {
                                        return row.fee_faban
                                    }
                                }
                            },
                            {
                                label: "其他扣费",
                                prop: "fee_other",
                                formatter: function (row, value, label, column) {
                                    if (row.fee_other == 0) {
                                        return 0
                                    } else {
                                        return row.fee_other
                                    }
                                }
                            },
                            {
                                label: "扣费合计",
                                prop: "fee_total",
                                formatter: function (row, value, label, column) {
                                    return (row.fee_daili) + (row.fee_faban) + (row.fee_other) + (row.fee_zhanwu);
                                    //tag[i].fee_daili + tag[i].fee_faban + tag[i].fee_other + tag[i].fee_zhanwu
                                }
                            },
                            {
                                label: "结算方式",
                                prop: "jstype"
                            },
                            {
                                label: "实付",
                                prop: "actual_pay",
                                formatter: function (row, value, label, column) {
                                    if (row.actual_pay == 0) {
                                        return 0
                                    } else {
                                        return row.actual_pay
                                    }
                                }
                            },
                            {
                                label: "结算员",
                                prop: "create_oper_name"
                            },
                            {
                                label: "结算时间",
                                prop: "create_time"
                            },
                            {
                                label: "作废操作员",
                                prop: "del_oper_name"
                            },
                            {
                                label: "作废时间",
                                prop: "update_time"
                            },
                        ]
                    }
                }
            };
        },
        methods: {
            querySearch(queryString, cb) {
                var restaurants = this.compList;
                var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            querySearchLine(queryString, cb) {
                var restaurants = this.lineList;
                var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            querySearchCarNum(queryString, cb) {
                var restaurants = this.carNumList;
                var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            createFilter(queryString) {
                return (restaurant) => {
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                };
            },
            getcompList() {
                this.postRequest("/sch/data/bus_company/listWithSpell").then(data => {
                    for (var item of data.data) {
                        this.compList.push({
                            value: item.name,
                            id: item.id
                        });
                    }
                })
            },
            getLineList() {
                this.postRequest("/sch/data/line/listWithSpell").then(data => {
                    for (var item of data.data) {
                        this.lineList.push({
                            value: item.name,
                            id: item.id
                        });
                    }
                })
            },
            getCarNumList() {
                this.postRequest("/sch/data/bus_vehicle/listWithSpell").then(data => {
                    for (var item of data.data) {
                        this.carNumList.push({
                            value: item.vehi_no
                        })
                    }
                })
            },
            accountPage(val) {
                this.accountTabled.page.currentPage = val;
                this.loadList();
            },
            getAccountTable() {
                this.postRequest("/fin/balance/sum/doRemoveGatherSingle", {
                    'type': 'all',
                }).then(data => {
                    console.log(data);
                    if(data.data[0] == '-1'){
                        this.$message.error(data.data[1]);
                    }else{
                        this.$message.error(data.data[1]);
                    }
                    /*this.accountTabled.page.total = data.data.totalRow;
                    this.accountTabled.data = data.data.list;*/
                })
            },
            loadList(){
                this.postRequest("/fin/balance/sum/list", {
                    order: 'desc',
                    rows: 10,
                    sort: 'create_time',
                    page: this.accountTabled.page.currentPage
                }).then(data => {
                    console.log(data);
                    this.accountTabled.page.total = data.data.totalRow;
                    var tag = data.data.list;
                    this.accountTabled.data = data.data.list;

                  /*  for(var i=0;i<tag.length;i++){
                        console.log(tag[i].fee_daili);
                        console.log(tag[i].fee_faban);
                        this.feeTatols.fee_total = (tag[i].fee_daili) + (tag[i].fee_faban);
                        // this.feeTatols.fee_total = tag[i].fee_daili + tag[i].fee_faban + tag[i].fee_other + tag[i].fee_zhanwu;
                    }
                    console.log(this.feeTatols.fee_total);*/


                })
            },
            check() {
                this.postRequest("/fin/balance/sum/list", {
                    filterRules: JSON.stringify([
                        {
                            "field": "gather_date",
                            "op": "dge",
                            "value": this.dateToString(this.formInline.dateFrom)
                        }, {"field": "gather_date", "op": "dle", "value": this.dateToString(this.formInline.dateTo)},
                        {"field": "line_names", "op": "cn", "value": this.formInline.line},
                        {"field": "no", "op": "eq", "value": this.formInline.num},
                        {"field": "custnames", "op": "cn", "value": this.formInline.comp},
                        {"field": "vehinos", "op": "cn", "value": this.formInline.line},
                        {"field": "del_flag", "op": "eq", "value": this.formInline.state}
                    ]),
                    rows: 10,
                    page: this.accountTabled.page.currentPage
                }).then(data => {
                    this.accountTabled.data = data.data.list;
                    this.accountTabled.page.total = data.data.totalRow;
                })
            },
            del() {
                this.getRequest("/fin/balance/sum/del?id=" + this.currentRow.id).then(data => {
                    this.msgShow(data, function () {
                        this.loadList();
                    });
                });
            },
            rowChange(val) {
                this.currentRow = val;
            },

        },
        computed: {},
        watch: {},
        mounted() {
            console.log("结算查询");
            this.$emit("sendActive", "5-5");
            this.loadList();
            this.getcompList();
            this.getLineList();
            this.getCarNumList();
        }
    };
</script>
<style scoped src="../../assets/css/financeManage/accountCheck.css">
</style>